package com.practice.StopWatch统计耗时;

import org.springframework.util.StopWatch;

/**
 * @program: tenghw-practice-demo
 * @author: tenghw
 * @create: 2024-01-22 16:32
 * @Version 1.0
 * @description:
 **/
public class Demo1 {
    public static void main1(String[] args) throws InterruptedException {
        StopWatch sw = new StopWatch();
        sw.start();
        Thread.sleep(1000);
        sw.stop();
        System.out.println(sw.getTotalTimeMillis());
    }

    public static void main(String[] args) throws InterruptedException {
        StopWatch sw = new StopWatch();
        sw.start("A");// 设置任务名称
        Thread.sleep(1000);
        sw.stop();
        sw.start("B");
        Thread.sleep(2000);
        sw.stop();
        System.out.println(sw.getLastTaskName());// 打印最后一个任务的名称
        System.out.println(sw.getLastTaskTimeMillis());
        System.out.println(sw.getTotalTimeMillis());
    }

    public static void main3(String[] args) throws InterruptedException {
        StopWatch sw = new StopWatch();
        sw.start("A");
        Thread.sleep(500);
        sw.stop();
        sw.start("B");
        Thread.sleep(300);
        sw.stop();
        sw.start("C");
        Thread.sleep(200);
        sw.stop();
        System.out.println(sw.getTotalTimeMillis());
        System.out.println(sw.prettyPrint());
    }

}